<template>
  <div class="withdrawal">
    <ComHeader title="提现记录" leftArrow="true"/>

    <div class="container">
      <scroll
        class="scroll"
        :data="drawalList"
        :pullup="isPullup"
        @scrollToEnd="searchMore"
        ref="suggest"
      >
        <ul>
          <li
            class="item flex-display flex-display-column"
            v-for="(item, index) in drawalList"
            :key="index"
          >
            <p class="item-info flex-display">
              <span>用户：{{item.nickname ? item.nickname : '-'}}</span>
              <span class="flex-num-one">-{{item.agent_tixian_fee}}元</span>
            </p>
            <span class="item-state">[{{item.state}}]</span>
            <span class="item-time">{{item.dealtime}}</span>
          </li>
          <loading v-show="isHasMore" title></loading>

          <p class="not-tit" v-if="drawalList.length && !isHasMore">————我是有底线的————</p>
        </ul>
        <div v-show="!isHasMore && !drawalList.length" class="no-result-wrapper">
          <span>抱歉，暂无提现记录</span>
        </div>
      </scroll>
    </div>
  </div>
</template>
<script>
import api from "@/fetch/api";
import ComHeader from "@/common/ComHeader";
import Scroll from "@/base/scroll/scroll";
import Loading from "@/base/loading/loading";
import axios from "axios";
export default {
  data() {
    return {
      isHasMore: true, // 是否需要上拉加载
      drawalList: [], // 列表数据
      isPullup: true, // 是否需要监听下拉加载
      previous: null, // 是否还有下一页
      page: 1, // 页码
      limit: 10 // 条数
    };
  },
  created() {
    // 获取数据
    this.getTxRecord();
  },
  methods: {
    // 获取数据
    getTxRecord(isMore = false) {
      
      const params = {
        page: this.page,
        limit: this.limit,
        uid: this.getUId(),
        type: 'tx'
      };
      api.getTxRecord(params).catch(res => {
        console.log(res)
        console.log('数据')
        if (res.status === 200) {
          if (!isMore && this.$refs.suggest) {
            this.$refs.suggest.scrollTo(0, 0);
          }
          if(res.data.msg == "该用户还没提现记录") {
            this.isHasMore = false
            return
          }
          this.drawalList = !isMore
            ? res.data.results
            : [...this.drawalList, ...res.data.results];
          this.isHasMore = res.data.next ? true : false;
          this.previous = res.data.next;
        }
      });
    },
    /**
     * @desc 是否需要下拉加载
     */
    searchMore() {
      if (this.previous) {
        this.page++;
        this.getTxRecord(true);
      }
    }
  },
  components: {
    Scroll,
    ComHeader,
    Loading
  }
};
</script>
<style lang="scss" scoped>
.withdrawal-info {
  border-top: 1px solid #e5e5e5;
}
.scroll {
  height: 100%;
  overflow: hidden;
}
.no-result-wrapper {
  position: absolute;
  width: 100%;
  top: 50%;
  text-align: center;
  color: #666;
  font-size: 0.35rem;
  transform: translateY(-50%);
}

.not-tit {
  width: 100%;
  height: 30px;
  line-height: 30px;
  text-align: center;
  color: #666;
  font-size: 0.35rem;
}
.container {
  position: fixed;
  width: 100%;
  top: 54px;
  bottom: 0;
  background: #fff;
  border-top: 1px solid #e5e5e5;
  .item {
    width: 100%;
    height: auto;
    position: relative;
    box-sizing: border-box;
    padding: 10px;
    border-bottom: 1px solid #e5e5e5;
    .item-info {
      display: flex;
      font-size: 0.38rem;
      font-weight: 600;
      span:last-child {
        display: block;
        flex: 1;
        text-align: right;
        color: #ff6c00;
      }
    }
    .item-state {
      display: inline-block;
      margin-top: 5px;
      margin-left: 12%;
    }
    .item-time {
      display: inline-block;
      margin-top: 5px;
      margin-left: 12%;
      color: #666;
    }
  }
}
</style>


